<?php

/**
 * Created by PhpStorm.
 * User: wu
 * Date: 2017/4/20
 * Time: 18:16
 */
class Userlogin
{
    private $resource;

    private $call_items;

    private $back_items;

    private $resource_id;

    public function __construct()
    {
        $this->resource = 'UserLogin';

        $this->call_items = array(
            "t" => time(),
            "k" => "",
            "uuid" => "",
            "platform" => "",
            "account" => ""
        );

        $this->back_items = array(
            "id" => "",                 //会员ID,
            "account" => "",            //会员手机号,
            "enterpriseId" => "",       //所属企业ID,
            "roleId" => "",             //角色ID,
            "roleName" => "",           //角色名称,
            "channelId" => "",          //渠道ID,
            "type" => "",               //会员类型(用户，客户),
            "channelName" => "",        //渠道名称,
            "tel" => "",                //联系方式,
            "service_hotline" => "",    //服务热线,
            "startPage" => ""
        );
    }

    public function set_call_items($obj = array())
    {
        if (isset($obj['t'])) {
            $this->call_items['t'] = $obj['t'];
        }
        if (isset($obj['uuid'])) {
            $this->call_items['uuid'] = isset($obj['uuid']) ? $obj['uuid'] : '';
        }
        if (isset($obj['platform'])) {
            $this->call_items['platform'] = isset($obj['platform']) ? $obj['platform'] : '';
        }
        if (isset($obj['account'])) {
            $this->call_items['account'] = isset($obj['account']) ? $obj['account'] : '';
        }
        if (isset($obj['password'])) {
            $private_key = md5($obj['password']);
            $public_key = md5($private_key . $this->call_items['account'] . $this->call_items['t']);
            $this->call_items['k'] = $public_key;
        }
        return $this->_get_url();
    }

    public function set_back_items($data = array())
    {
        if (isset($data['id'])) {
            $this->back_items['id'] = $data['id'];
        }
        if (isset($data['account'])) {
            $this->back_items['account'] = $data['account'];
        }
        if (isset($data['roleId'])) {
            $this->back_items['roleId'] = $data['roleId'];
        }
        if (isset($data['roleName'])) {
            $this->back_items['roleName'] = $data['roleName'];
        }
        if (isset($data['channelId'])) {
            $this->back_items['channelId'] = $data['channelId'];
        }
        if (isset($data['type'])) {
            $this->back_items['type'] = $data['type'];
        }
        if (isset($data['channelName'])) {
            $this->back_items['channelName'] = $data['channelName'];
        }
        if (isset($data['tel'])) {
            $this->back_items['tel'] = $data['tel'];
        }
        if (isset($data['service_hotline'])) {
            $this->back_items['service_hotline'] = $data['service_hotline'];
        }
        if (isset($data['startPage'])) {
            $this->back_items['startPage'] = $data['startPage'];
        }
    }

    public function set_resource_id($id)
    {
        $this->resource_id = $id;
        return $this->_get_url();
    }

    public function get_call_items()
    {
        return $this->call_items;
    }

    public function get_back_items()
    {
        return $this->back_items;
    }

    public function get_resource_id()
    {
        return $this->resource_id;
    }

    private function _get_url()
    {
        if ($this->resource_id) {
            return $this->resource . '/' . $this->resource_id . '/';
        } else {
            return $this->resource . '/';
        }
    }
}